package com.glela.platform.service.impl;

import com.glela.platform.mapper.UserRedPacketMapper;
import com.glela.platform.service.UserRedPacketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service("userRedPacketService")
public class UserRedPacketServiceImpl implements UserRedPacketService {

    @Autowired
    private UserRedPacketMapper userRedPacketMapper;

    @Override
    public String sumTotalRedPacketByUserId(long userId) {

        Long totalAmount = userRedPacketMapper.sumTotalRedPacketByUserId(userId, new Date());

        if (totalAmount == null) {

            return "0";
        }
        return BigDecimal.valueOf(totalAmount.longValue()).divide(BigDecimal.valueOf(100)).toString();
    }
}
